﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace FillWordDataByTemplate
{
    class Class1
    {
        private void test()
        {
            MatchCollection mc = Regex.Matches("A1249T3S", "[A-Za-z]");
            //MatchCollection mc = Regex.Matches("A1249T3S", "[\\d]");
            foreach (Match m in mc)
            {
                string a = Convert.ToString(m.Groups["0"].Value);
                Debug.WriteLine(a);
            }
        }

        /// <summary>
        /// 下面的代码实现将文本中的UBB超级链接代码替换为HTML超级链接代码
        /// </summary>
 
        public void UBBDemo()
        {
            string text = "[url=http://zhoufoxcn.blog.51cto.com][/url][url=http://blog.csdn.net/zhoufoxcn]周公的专栏[/url]";
            Console.WriteLine("原始UBB代码：" + text);

            Regex regex = new Regex(@"(\[url=([ \S\t]*?)\])([^[]*)(\[\/url\])", RegexOptions.IgnoreCase);

            MatchCollection mc = regex.Matches(text);
            foreach (Match match in mc)
            {
                //
                Debug.WriteLine("match=" + match.Value);
                foreach (Group g in match.Groups)
                {
                    Debug.WriteLine("Group = " + g.Value);
                }

                //
                string linkText = string.Empty;

                //如果包含了链接文字，如第二个UBB代码中存在链接名称，则直接使用链接名称
                if (!string.IsNullOrEmpty(match.Groups[3].Value))
                {
                    linkText = match.Groups[3].Value;
                }
                else//否则使用链接作为链接名称
                {
                    linkText = match.Groups[2].Value;
                }
                text = text.Replace(match.Groups[0].Value, "" + linkText + "");
            }
            Console.WriteLine("替换后的代码：" + text);
        }

    }
}

/*
 * POI读写Word docx文件 
 * https://www.cnblogs.com/liuchaogege/p/5772725.html
 * 
 *
 * 
 */

//https://www.zhangshengrong.com/p/QrXebYKo1d/

